package com.binvshe.binvshe.organization;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;

import com.binvshe.binvshe.R;
import com.binvshe.binvshe.common.image.IML;
import com.binvshe.binvshe.mine.corporation.MyClubActivity;
import com.binvshe.binvshe.organization.entity.OrgItemEntity;
import com.pachong.android.baseuicomponent.adapter.RecyclerViewBaseAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/9/18
 */
public class OrgListAdapter extends RecyclerViewBaseAdapter<OrgItemEntity> {


    public OrgListAdapter(Context con) {
        super(con);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View view = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.item_org_list, parent, false);
        return new VH(view);
    }

    @Override
    public void onBindHolder(RecyclerView.ViewHolder holder, int position) {
        VH mHolder = (VH) holder;
        OrgItemEntity data = getData().get(position);
        IML.load(getContext(), mHolder.mCivOrgHead, data.getPortrait());
        mHolder.mTvOrgName.setText(data.getName());
//        mHolder.mTvOrgDesc.setText(data.getSign());
        mHolder.mTvOrgDesc.setText(data.getCate_name());
        mHolder.mTvOrgPlace.setText(data.getCity());
        setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ClubCenterActivity.start(getContext(), getData().get(position).getId());
            }
        });
    }


    class VH extends RecyclerView.ViewHolder {
        @Bind(R.id.civOrgHead)
        CircleImageView mCivOrgHead;
        @Bind(R.id.tvOrgName)
        TextView mTvOrgName;
        @Bind(R.id.tvOrgDesc)
        TextView mTvOrgDesc;
        @Bind(R.id.tvOrgPlace)
        TextView mTvOrgPlace;

        public VH(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}